package com.hardroid.workload.utils;

import java.util.ArrayList;

import com.hardroid.workload.ui.widget.EmployerItemView;
import com.hardroid.workload.ui.widget.TallyItemView;
import com.hardroid.workload.workcalc.Employer;
import com.hardroid.workload.workcalc.Tally;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class TalliesAdapter extends BaseAdapter{

	private ITallySelected iTallySelected;
	private ArrayList<Tally> lTally;
	private Context context;
	
	public TalliesAdapter(Context context, ArrayList<Tally> lTally, ITallySelected iTally) {
		this.lTally = lTally;
		this.context = context;
		this.iTallySelected = iTally;
	}
	
	@Override
	public int getCount() {
		return lTally.size();
	}

	public ArrayList<Tally> getTallies(){
		return lTally;	
	}
	
	@Override
	public Object getItem(int position) {

		return lTally.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView!=null){
			((TallyItemView)convertView).setTally((Tally)getItem(position), position);
		}else{
			convertView = new TallyItemView(context,(Tally) getItem(position), position, iTallySelected);	
		} 
		return convertView;
	}

}
